<?php

class Listener_Order_Canceled_Email extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            //推送到队列执行
            Queue::in('default', Listener_Order_Canceled_Email::class, $args);
        } else {
            $self->perform();
        }

    }

    public function perform()
    {
        $args    = $this->args;
        $ordersn = $args['ordersn'];

        $order = DB::select()
            ->from('member_order')
            ->where('ordersn', '=', $ordersn)
            ->execute()
            ->current();
        if ($order) {
            $result = St_EmailService::send_product_order_email(St_NoticeCommon::PRODUCT_ORDER_CANCEL_MSGTAG, $order);

            St_Log::write('邮件通知', array('ordersn' => $ordersn, 'result' => $result), 'event/order_canceled/log');
        }
    }

}